import React from 'react';
import { notification } from 'antd';

export interface P {

}

export interface S {
  hasError: boolean;
}

class ErrorBoundary extends React.Component<P, S> {
  state = {
    hasError: false
  }

  static getDerivedStateFromError(error) {
    return { hasError: true };
  }

  componentDidCatch(error, info) {

    // logErrorToMyService(error, info);
    notification['error']({
      message: error,
      description: info,
    });
  }

  render() {
    if (this.state.hasError) {
      return <h1>发生错误了</h1>;
    }

    return this.props.children; 
  }
}

export default ErrorBoundary;
